package file;

import java.io.File;
import java.io.FileFilter;

/**
 * 获取./src/file目录下的所有名字以"D"开头的子项
 */
public class Test {
    public static void main(String[] args) {
        File file=new File("./src/file");
        if (file.isDirectory()){
            FileFilter filter=new FileFilter() {
                @Override
                public boolean accept(File file) {
                    String name=file.getName();
                    System.out.println("正在过滤:"+name);
                    return name.startsWith("D");
                }
            };
            File[] subs=file.listFiles(filter);
            for (int i = 0; i < subs.length; i++) {
                File s=subs[i];
                System.out.println(s.getName());
            }

        }

    }
}

